<?php
require_once '../config.php';

class FacebookToolboxTest extends PHPUnit_Framework_TestCase
{
    /**
     * like a singleton
     */         
    protected static $facebook_toolbox;
    
    /**
     * Init the FacebookToolbox 
     */         
    public static function setUpBeforeClass(){
        $params = array(
                'appId'  => FB_APP_ID,
                'secret' => FB_APP_SECRET,
                'cookie' => true,
            );
        self::$facebook_toolbox = new FacebookToolbox($params);
        self::$facebook_toolbox->setDebugLevel(APP_DEBUG_TEST_LEVEL);  
        self::$facebook_toolbox->getAppAccessToken();                           // init the app_access_token
            
    }
    
    /**
     * Free Resources
     */         
    public static function tearDownAfterClass(){
        self::$facebook_toolbox = null;
    }
        
    function setUp() {}
    function tearDown() {}
    
    /**
     * Check if the facebook_toolbox it's initializated
     */         
    public function testInitialization(){
        $this->assertNotNull(self::$facebook_toolbox);
    }
    
    /**
     * Check the format of the access_token 
     */         
    public function testGetAppAccessToken(){
        $this->assertContains('access_token=',self::$facebook_toolbox->getAppAccessToken());
    }
   
    public function testGetLoginUrl(){
        $_SERVER['HTTP_HOST'] = str_ireplace('http://','',FB_APP_BASE_URL);
        $_SERVER['REQUEST_URI'] = '/index.php';
        
        $url = self::$facebook_toolbox->getLoginUrl();
        $this->assertTrue( stripos($url,'dialog/oauth')!==false );
    }
    
    public function testIsNotLogued(){
        $this->assertFalse( self::$facebook_toolbox->isLogued() > 0 );
    }
    
    public function testIsLogued(){
        self::$facebook_toolbox->setAccessToken(FB_TEST_ACCESS_TOKEN);
        $this->assertTrue( self::$facebook_toolbox->isLogued() >0 );
    }
    
    public function testNotLikePage(){
        $this->assertTrue( self::$facebook_toolbox->checkLikePage('215804355154731') == 0 );
    }
    
 
    public function testCheckPrivilegies(){
        $this->assertTrue( self::$facebook_toolbox->checkPrivilegies('publish_stream,user_likes') > 0 );
    }
    public function testCheckNoPrivilegies(){
        $this->assertTrue( self::$facebook_toolbox->checkPrivilegies('offline_access') == 0 );
    }        
    
    public function testPost(){
    	$params=array(
    		'message'=> "testssssssss I have just entered for a chance to win $25,000 in the Rogers Smart Home Monitoring Giveaway. Use Smart Code 3286 to enter at http://www.smarthomegiveaway.com/?code=3286",
    		'display'=> 'iframe',
    		'caption'=>"www.smarthomegiveaway.com",	
    		'name'=> "Rogers Smart Home Monitoring",
    		'picture'=> 'http://www.smarthomegiveaway.com/images/encabezado-fb.png',
    		'link'=> "http'=>//www.smarthomegiveaway.com/?code=3286",
    		'description'=> "Enter your SMART CODE for a chance to win $25,000!",
    	);
    	self::$facebook_toolbox->post(FB_TEST_FBID,$params);
    }
    
}